﻿using DataSync.Common;
using DataSync.Proc;
using DataSync.Proc.CustParse;
using DataSync.Proc.Reader;
using DataSync.Proc.Writer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataSync.Proc
{
    class InterfaceFactory
    {
        public static IDataSyncReader GetReader(string type)
        {
            switch (type.ToUpper())
            {
                case "FTP":
                case "FTPFILE":
                    return new FTPFileReader();
                case "LOCALFILE": return new LocalFileReader();
                case "DB": return new DBReader();
                case "CONSOLE": return new ConsoleReader();
                default:
                    break;
            }
            return null;
        }
        public static IDataSyncWriter GetWriter(string type)
        {
            switch (type.ToUpper())
            {
                case "CONSOLE": return new ConsoleWriter();
                case "DB": return new DBWriter();
                case "ORACLEDB": return new OracleDBWriter();
                default:
                    break;
            }
            return null;
        }


        public static ICustParse GetCustParse(string type)
        {
            switch (type)
            {
                case "FileNameDateCustParse":
                    return new FileNameDateCustParse();
                case "RegexCustParse":
                    return new RegexCustParse();
                case "SubstrCustParse":
                    return new SubstrCustParse();
                case "DataEnumCustParse":
                    return new DataEnumCustParse();
                case "DESEncryptCustParse":
                    //DES加密
                    return new DESEncryptCustParse();
                case "DESDecryptCustParse":
                    //DES解密
                    return new DESDecryptCustParse();
                default:
                    break;
            }
            return null;
        }

        /// <summary>
        /// 获取任务
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ITask GetTask(TaskConf conf)
        {
            if (!string.IsNullOrEmpty(conf.Type))
            {
                switch (conf.Type)
                {
                    case "DataCollect":
                        return new DataCollectBase(conf);
                    case "DataFileClean":
                        return new DataFileClean(conf);
                    case "DBSqlExe":
                        return new DBSqlExe(conf);
                }
            }
            throw new ApplicationException(string.Format("未实现的任务方式:{0}", conf.Type));
        }
    }
}
